<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.talkweb.ncfw.web.common.WebAttributeConst" %>
<%@ page import="org.springframework.security.core.AuthenticationException" %>
<%@ page import="com.talkweb.ncfw.web.common.MyWebAttributeConst" %>
<%@ page import="org.apache.commons.codec.binary.Hex"%>
<%@ page import="java.security.interfaces.RSAPublicKey"%>
<%@ page import="com.talkweb.ncfw.utils.encrypt.RSAUtils"%>
<%@ page import="com.talkweb.ncfw.security.SecurityHelper"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>企业信息管理系统-登录页面</title>
<%
	if (SecurityHelper.getCurrentUser() != null) {%>
		<script type="text/javascript">
		<!--
			window.location.href = './index.jsp';
		//-->
		</script>
	<%}
	String path 	= request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	String info		= request.getParameter("info");
	String lastLoginUserName = (String)session.getAttribute(WebAttributeConst.LOGIN_LAST_USERNAME_KEY);
	if (lastLoginUserName == null) {
		lastLoginUserName = "";
	}
	Object modulus	= session.getAttribute(MyWebAttributeConst.PUBLIC_KEY_MODULUS);
	Object exponent	= session.getAttribute(MyWebAttributeConst.PUBLIC_KEY_EXPONET);
	if (modulus == null || exponent == null) {
		RSAPublicKey publicKey = RSAUtils.getDefaultPublicKey();
		modulus		= new String(Hex.encodeHex(publicKey.getModulus().toByteArray()));
		exponent	= new String(Hex.encodeHex(publicKey.getPublicExponent().toByteArray()));
		session.setAttribute(MyWebAttributeConst.PUBLIC_KEY_MODULUS, modulus);
		session.setAttribute(MyWebAttributeConst.PUBLIC_KEY_EXPONET, exponent);
	}
 %>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #016aa9;
	overflow:hidden;
}
.STYLE1 {
	color: #000000;
	font-size: 12px;
}
-->
</style>

<script type="text/javascript" src="<%=basePath%>foundation/js/RSA.js"></script>  
<script type="text/javascript" src="<%=basePath%>foundation/js/BigInt.js"></script>  
<script type="text/javascript" src="<%=basePath%>foundation/js/Barrett.js"></script> 
<script type="text/javascript">
<!--
var info = '<%=info%>';
if (info == 'AuthenticationFailure') {
	alert('登录失败, 登录帐号与密码不一致或登录帐号失效.');
}

function onLogin () {
	var username = document.getElementById('j_username');
	var password = document.getElementById('password');
	if (username.value == '') {
		alert('登录帐号不能为空!');
		username.focus();
		return;
	}
	if (password.value == '') {
		alert('密码不能为空!');
		password.focus();
		return;
	}
	setMaxDigits(130);
	var key 			= new RSAKeyPair('<%=exponent%>', '', '<%=modulus%>');
	var pwd 			= password.value;
	var encrptPassword	= encryptedString(key, pwd);
	document.getElementById('j_password').value = encrptPassword;
	document.getElementById('loginForm').submit();
}

function onReset () {
	document.getElementById('loginForm').reset();
}

//-->
</script>
</head>

<body>
<form method="post" id="loginForm" action="<%=path%>/j_spring_security_check">
<input type="hidden" name="j_password" id="j_password" value=""/>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><table width="962" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="235" background="images/login_03.gif">&nbsp;</td>
      </tr>
      <tr>
        <td height="53"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="394" height="53" background="images/login_05.gif">&nbsp;</td>
            <td width="206" background="images/login_06.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="16%" height="25"><div align="right"><span class="STYLE1">用户名</span></div></td>
                <td width="57%" height="25"><div align="center">
                  <input type="text" name="j_username" id="j_username" value="sysadmin" style="width:105px; height:17px; background-color:#292929; border:solid 1px #7dbad7; font-size:12px; color:#6cd0ff">
                </div></td>
                <td width="27%" height="25">&nbsp;</td>
              </tr>
              <tr>
                <td height="25"><div align="right"><span class="STYLE1">密码</span></div></td>
                <td height="25"><div align="center">
                  <input type="password" name="password" id="password" value="000000" style="width:105px; height:17px; background-color:#292929; border:solid 1px #7dbad7; font-size:12px; color:#6cd0ff">
                </div></td>
                <td height="25"><div align="left"><a href="javascript: onLogin();"><img src="images/dl.gif" width="49" height="18" border="0"></a></div></td>
              </tr>
            </table></td>
            <td width="362" background="images/login_07.gif">&nbsp;</td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td height="213" background="images/login_08.gif">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
</form>
</body>
</html>
